Skip to content

Conversation

hieblmi
Copy link
Collaborator

@hieblmi hieblmi commented Sep 30, 2025

The fast flag enables the client to access change of a fractional amount swap faster. Since batching can delay the publishing of the on-chain swap transaction the client can pay a fee for faster access to optional change. A few examples of how this PR changes the command line arguments for fractional swaps.

loop static in 500000                                                 // Loop in exactly 500000 sats; auto-select deposits to cover the amount.
loop static in 500000 --fast                                         // Same as above, but request fast publication behavior (may cost more).
loop static in --all                                                 // Loop in the full balance of all eligible static-address deposits.
loop static in 500000 --all                                         // Loop in exactly 500000, select all eligible static-address deposits.
loop static in --utxo txid:vout                                     // Loop in exactly the specified deposit UTXO.
loop static in --utxo txid:vout --utxo txid:vout ...                 // Loop in the union of the listed deposit UTXOs.
loop static in 500000 --utxo txid:vout --utxo txid:vout ... --fast     // 500000 from selected deposits with fast publication behavior.

Copy link

Summary of Changes

Hello @hieblmi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the static address loop-in functionality by introducing a 'fast' option. This feature allows users to prioritize the speed of on-chain transaction publishing for fractional change amounts, enabling quicker access to funds by bypassing standard batching delays. The implementation involves comprehensive updates across the system, from the command-line interface and API definitions to the database schema and the sweep batching mechanism, ensuring that the 'fast' preference is consistently handled and applied.

Highlights

  • Fast Flag Introduction: A new 'fast' flag has been introduced for static address loop-in swaps, allowing clients to request expedited publishing of on-chain transactions, particularly for change outputs.
  • Expedited Publishing: When the 'fast' flag is enabled, the sweep batcher will bypass its usual initial delay mechanism, leading to immediate publication of the swap transaction, albeit potentially at a higher fee.
  • Database Persistence: The 'fast' flag is now stored in the database for static address swaps, ensuring that the client's preference for expedited publishing is recorded and persisted.
  • API and CLI Integration: The new 'fast' flag has been integrated across the client's command-line interface, internal API definitions (gRPC and Swagger), and server-side logic to propagate and act upon this new preference.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a --fast flag for static address loop-in swaps, enabling expedited publishing of the on-chain transaction in exchange for a potentially higher fee. The implementation correctly propagates this flag from the CLI and RPC layers down to the server request, and the database schema is updated accordingly. The main feature appears to be well-implemented.

Additionally, a similar fast flag mechanism has been added to the sweepbatcher for client-side sweeps. However, this functionality seems to be unused in the current changes, which could lead to confusion. I've added a review comment to seek clarification on this part of the implementation.


/*
If set to true the server will immediately publish the swap in exchange for
a higher fee. This can be useful if the client expects change from a swap.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only available for swaps with change...

// has to pay when the sweeping transaction is broadcast.
uint32 num_static_address_deposits = 7;

// If set, request the server to use fast publication behavior.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add description

Copy link
Member

@bhandras bhandras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

@hieblmi hieblmi force-pushed the fast-flag branch 3 times, most recently from 407d912 to d5567e2 Compare October 6, 2025 16:19
Copy link
Collaborator

@starius starius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🌴
Great work!

I left few proposals. The most important one is in sweepbatcher to let fast swaps batching. I proposed a way how to do it keeping the change small.

bool auto_select_deposits = 10;

/*
If set to true the server will immediately publish the swap in exchange for
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a note that this field is only allowed for static loop-ins. If it is used in a regular loop-in, loopd should return an error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// has to pay when the sweeping transaction is broadcast.
uint32 num_static_address_deposits = 7;

// If set, request the server to use fast publication behavior.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a note that this field is only allowed for static loop-ins. If it is used in a regular loop-in, loop server is expected to return an error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1,2 @@
-- Drop 'fast' flag from static_address_swaps
ALTER TABLE static_address_swaps DROP COLUMN fast; No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line end is missing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -0,0 +1,2 @@
-- Add 'fast' flag to static_address_swaps, default false
ALTER TABLE static_address_swaps ADD COLUMN fast BOOLEAN NOT NULL DEFAULT false; No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line end is missing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

// logged as a warning.
type InitialDelayProvider func(ctx context.Context, numSweeps int,
value btcutil.Amount) (time.Duration, error)
value btcutil.Amount, fast bool) (time.Duration, error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, true is never passed to this callback. If fast=true, there is a separate code path in spinUpBatch:

if cfg.initialDelayProvider == nil || fast {
		cfg.initialDelayProvider = zeroInitialDelay
	}

I propose to use this new argument instead of making a special case in spinUpBatch.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast=true is passed on the delay provider on the server side.

Comment on lines +984 to +988
// If fast is set, we spin up a new batch which is published
// immediately.
if fast {
return b.spinUpNewBatch(ctx, sweeps, true)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prevents batching fast sweeps. It makes sense to batch them to save on fees.

I propose to remove this if and track fastness per sweep. We can add the flag to sweep and modify batch.Run method to pass fast to b.cfg.initialDelayProvider call (the only place where initialDelayProvider is called).

It makes sense to add method isFast() for batch similar to isUrgent and call if from batch.Run for convenience.

And we don't need to pass fast to spinUpBatch anymore, because we can always deduce it from sweeps.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion to briefly delay the publication of a fast batch to gather more fast swaps. This will be addressed in a separate PR.

Private: req.Private,
Initiator: defaultLoopdInitiator,
NumDeposits: uint32(numDeposits),
Fast: req.Fast,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to check here that if req.Fast is set, we make sure that the swap is static. Otherwise fail. Just as a sanity check measure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a sanity check.

Usage: "expedited publishing of the change output if " +
"the swap creates one. This results in a " +
"higher swap fee.",
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to rephrase it to make the purpose clearer:

Usage: "complete the swap faster by paying a higher fee, so the change output is available sooner",

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added this description

"swapped from the selected deposits. If there" +
"is change it is sent back to the static " +
"address.",
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep previous flag as well? So it is possible to set it via --amount. Some people may prefer this, e.g. in scripts where each argument is on a separate line. Positional argument is good for manual use.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, I re-added the flag.

@starius
Copy link
Collaborator

starius commented Oct 7, 2025

CLI is broken:

$ ~/fast-flag/loop --network signet static in --utxo b7c34d293e816cdcb102f1e2dcfaba9c4f553356a881fcc042ad6522da972176:0
On-chain fees for static address loop-ins are not included.
They were already paid when the deposits were created.

Previously deposited on-chain:                  0 sat
Receive off-chain:                          -1568 sat
Estimated total fee:                         1568 sat

CONTINUE SWAP? (y/n): n

Also:

$ ~/fast-flag/loop --network signet static in --all
On-chain fees for static address loop-ins are not included.
They were already paid when the deposits were created.

Previously deposited on-chain:                  0 sat
Receive off-chain:                          -6399 sat
Estimated total fee:                         6399 sat

CONTINUE SWAP? (y/n):

I think this also exists in master.

It seems to pass QuoteRequest{Amt: 0} in displayInDetails. We have variable allDeposits in that function (staticAddressLoopIn), we can deduce the amount from it if user doesn't specify anything.

@hieblmi
Copy link
Collaborator Author

hieblmi commented Oct 7, 2025

CLI is broken:

Yes thanks, I noticed this bug a while ago and have a fix on my todo list. Its because the quoting part doesn't have access to the utxo amount yet.

@hieblmi hieblmi merged commit c1ab1f3 into lightninglabs:master Oct 7, 2025
4 checks passed
@hieblmi hieblmi deleted the fast-flag branch October 7, 2025 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants